package com.baizhi.controller.v2;

import com.baizhi.entity.Pet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

@RestController("userControllerV2")
@RequestMapping("/v2/users")
public class UserController {
    private static final Logger logger = LoggerFactory.getLogger(UserController.class);

    /**
     * 获取这个人所有宠物
     */
    @GetMapping("/{id}/pets")
    public ResponseEntity<List<Pet>> pets(@PathVariable Integer id) {
        logger.debug("查询人id：{}", id);
        List<Pet> pets = Arrays.asList(
                new Pet(21, "小红帽", 23),
                new Pet(22, "小猪", 22)
        );
        return new ResponseEntity<>(pets, HttpStatus.OK);
    }

    /**
     * 获取这个人某个宠物
     */
    @GetMapping("/{id}/pets/{pid}")
    public ResponseEntity<Pet> pet(@PathVariable Integer id, @PathVariable Integer pid) {
        logger.debug("查询人id：{}，宠物id：{}", id, pid);
        Pet pet = new Pet(pid, "小红帽", 23);
        return new ResponseEntity<>(pet, HttpStatus.OK);
    }
}
